function timer(exerciseID,time,update,complete) {
	var start = new Date().getTime();
	var interval = setInterval(function() {
		var now = time-(new Date().getTime()-start);
		if($("#resolve_"+exerciseID).val()=='stop') {
			clearInterval(interval);
		}
		if( now <= 0) {
			clearInterval(interval);
			complete();
		}
		else update(dis(Math.floor(now/1000)));
	},100); // the smaller this number, the more accurate the timer will be
}
function dis(secs) {
 	var disp;
 	
 	var hour = parseInt(secs/3600); 	
 	var minute =parseInt((secs -hour*3600)/60); 	
 	var second = secs%60;
 	
 	if(hour <= 9) {
  		disp = " 0";
 	} else {
  		disp = " ";
 	}
 	disp += hour + ":";
 	
 	if(minute <= 9) {
  		disp += "0";
 	} else {
  		disp += " ";
 	}
 	
 	disp += minute + ":";
 	
 	if(second <= 9) {
  		disp += "0" + second;
 	} else {
  		disp += second;
 	}
 	return(disp);
}